<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>博客列表页</title>
    <link rel="stylesheet" href="./css/normal.css">
    <link rel="stylesheet" href="./css/list.css">
    <script src="./js/common.js"></script>
    <style>
        
        .nav{
            position: fixed;
            top: 0;
            left: 0;
            right: 0;
            height: 50px;
        }
        .container{
            padding-top: 80px;
            height: auto;
        }
        .container-right{
            width: auto;
        }
        .blog-pagnation-wrapper{
            height: 40px;
            margin: 16px 0;
            text-align: center;
        }
        .blog-pagnation-item{
            display: inline-block;
            padding: 8px;
            border: 1px solid #d0d0d5;
            color: #333;
        }
        .blog-pagnation-item:hover{
            background: #4e4eeb;
            color: #fff;
        }
        .blog-pagnation-item.actvie{
            background: #4e4eeb;
            color: #fff;
        }

    </style>
</head>

<body>
    <div class="nav">
        <img src="./pic/dog.png" alt="">
        <span class="blog_title">我的博客系统</span>
        <span class="space"></span>
        <a href="#" class="nav_span">主页</a>
        <a href="./edit.html" class="nav_span">写博客</a>
        <a href="reg.html" class="nav_span">注册</a>
        <a  class="nav_span" onclick="logout()">注销</a>
      
    </div>

    <div class="container">
        <div class="left">
            <div class="card">
                <img src="./pic/src.jpg" alt="">

                <h3></h3>
                <a href="">Github地址</a>
                <div class="row">
                    <span>文章</span>
                    <span>分类</span>
                </div>
                <div class="row">
                    <span>2</span>
                    <span>1</span>
                </div>
            </div>
        </div>

        <div class="right">
            <div id="blogListDiv">

            </div>
            
            <hr>
            <div class="blog-pagnation-wrapper">
                <button onclick="goFirstPage()" class="blog-pagnation-item">首页</button> 
                <button onclick="goBeforePage()" class="blog-pagnation-item">上一页</button>  
                <button onclick="goNextPage()" class="blog-pagnation-item">下一页</button>
                <button onclick="goLastPage()" class="blog-pagnation-item">末页</button>
            </div>
        </div>
    </div>
    <script src="js/jquery-3.3.1.min.js"></script>
   

    <script>
        var pindex = 1;
        var psize = 5;
        var pcount = 1;
        pindex = (getUrlValue("pindex")==""?1:getUrlValue("pindex"));

        $.ajax({
            type: "post",
            url: "blog/getallbypage",
            data:{"pindex":pindex,"psize":psize},
            success: function (result) {
                if(result.code==200 && result.data!=null && result.data.list.length>0){
                    var finalHtml = "";
                    for(var data of result.data.list){
                        finalHtml+= '<div class="blog">';
                        finalHtml+='<div class="title">'+data.title+'</div>';
                        finalHtml+='<div class="date">'+data.createTime+'</div>';
                        finalHtml+='<div class="desc">'+data.content+'</div>';
                        finalHtml+='<a href="detail.html?id='+data.id+'" class="detail">查看全文&gt;&gt;</a>';
                        finalHtml+='</div>';
                        finalHtml+='<hr>';
                    }
                    $("#blogListDiv").html(finalHtml);
                    pcount = result.data.pcount;
                }
            },
            error:function(error){
                if(error!=null && error.status == 401   ){
                    alter("用户未登录");
                    location.href("/login.html");
                }
            }

        })
        var url = "/user/getlogininfo"
        getUserInfo(url);
  // 跳转到首页
  function goFirstPage(){
            if(pindex<=1){
                alert("当前已经在首页了");
                return;
            }
            location.href = "blog_list.html";
        }
        // 点击上一页按钮
        function goBeforePage(){
            if(pindex<=1){
                alert("当前已经在首页了");
                return;
            }
            pindex = parseInt(pindex) -1;
            location.href ="blog_list.html?pindex="+pindex;
        }
        function goNextPage(){
            if(pindex>=pcount){
               alert("已经在末页了");
               return; 
            }
            pindex = parseInt(pindex)+1;
            location.href ="blog_list.html?pindex="+pindex;
        }
        function goLastPage(){
            if(pindex>=pcount){
               alert("已经在末页了");
               return; 
            }
            location.href ="blog_list.html?pindex="+pcount;
        }
    </script>
</body>

</html>